﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Globalization;
using Microsoft.Advertising.Mobile.UI;
using System.ComponentModel;
using Common.Library;
using OnlineVideos.Library;
using OnlineVideos.UI;
using OnlineVideos.Data;
using OnlineVideos.Common;
using Common.Utilities;
using OnlineVideos.Entities;

namespace OnlineVideos.Views
{
    public partial class MoviesList : PhoneApplicationPage
    {
        string[] a4;
       
        public MoviesList()
        {
            InitializeComponent();
            if (ResourceHelper.AppName != Apps.Indian_Cinema_Pro.ToString() && ResourceHelper.AppName != Apps.Kids_TV_Pro.ToString() && ResourceHelper.AppName != Apps.Story_Time_Pro.ToString())
            LoadAds();
            a4 = Application.Current.Resources["ContextMenu"].ToString().Split(',');
            tblkVideosTitle.Text = a4[2].ToString();
        }
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.EndTimedEvent("MoviesList Page");
            }
            catch (Exception ex)
            {
                
                 Exceptions.SaveOrSendExceptions("Exception in OnNavigatedFrom Method In MoviesList.cs file.", ex);
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogPageView();
            }
            catch (Exception ex)
            {

               Exceptions.SaveOrSendExceptions("Exception in OnNavigatedTo Method In MoviesList.cs file.", ex);
            }
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                FlurryWP8SDK.Api.LogEvent("MoviesList Page", true);
            _performanceProgressBar.IsIndeterminate = true;
            BackgroundHelper bwHelper = new BackgroundHelper();

            bwHelper.AddBackgroundTask(
                                        (object s, DoWorkEventArgs a) =>
                                        {
                                            a.Result = OnlineShow.GetperentList();
                                        },
                                        (object s, RunWorkerCompletedEventArgs a) =>
                                        {
                                            lbxRemoveList.ItemsSource = (List<ShowList>)a.Result;
                                            _performanceProgressBar.IsIndeterminate = false;
                                        }
                                      );
            bwHelper.RunBackgroundWorkers();
         
            }
            catch (Exception ex)
            {
                
                 Exceptions.SaveOrSendExceptions("Exception in PhoneApplicationPage_Loaded Method In MoviesList.cs file.", ex);
            }
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
            ListBoxItem selectedListBoxItem = this.lbxRemoveList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;
            if (selectedListBoxItem == null)
                return;
            OnlineShow.SaveRemoveVideos((selectedListBoxItem.Content as ShowList).ShowID);
            lbxRemoveList.ItemsSource = OnlineShow.GetperentList();
        }
            catch (Exception ex)
            {
                
                   Exceptions.SaveOrSendExceptions("Exception in MenuItem_Click Method In MoviesList.cs file.", ex);
            }
        }

        #region "Common Methods"

        private void LoadAds()
        {
            try
            {
                PageHelper.LoadAdControl(LayoutRoot, adstackpl, 2);
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in LoadAds Method In SongDetails file", ex);
                string excepmess = "Exception in LoadAds Method In SongDetails file.\n\n" + ex.Message + "\n\n StackTrace :- \n" + ex.StackTrace;
            }

        }

        #endregion
       
        private void MenuItem1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
            ListBoxItem selectedListBoxItem = this.lbxRemoveList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;
            if (selectedListBoxItem == null)
                return;
            AppSettings.ShowID = (selectedListBoxItem.Content as ShowList).ShowID.ToString();

            NavigationService.Navigate(NavigationHelper.getSongListPage(AppSettings.ShowID));
        }
            catch (Exception ex)
            {
                
              Exceptions.SaveOrSendExceptions("Exception in MenuItem1_Click Method In MoviesList.cs file.", ex);
            }
        }
        private void imgTitle_MouseEnter(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.MainPanoramaPage);
        }
    }
}